/*! 
 * Header file for the force registry.
 *
 * \author Devis Rossini
 * \date 18 March 2012
 */ 
#ifndef PHXFORCEREGISTRY_H_INCLUDE_GUARD
#define PHXFORCEREGISTRY_H_INCLUDE_GUARD

#include "PhxRigidBody.h"
#include "PhxForceGenerator.h"

#include <vector>

namespace phx
{
	/*!
	 * Keeps track of one force generator and the body it
	 * applies to.
	 */
	struct ForceRegistration
	{
		RigidBody* body;
		ForceGenerator* fg;
	};

	/*!
     * Holds all the force generators and the bodies they apply to.
     */
    class ForceRegistry
    {
    protected:

        typedef std::vector<ForceRegistration> Registry;
        
		/*!
         * Holds the list of registrations.
         */
		Registry mRegistrations;

    public:

        /*!
         * Registers the given force generator to apply to the
         * given body.
         */
        void Add(RigidBody* body, ForceGenerator* fg);

		/*!
         * Registers the given force generator to apply to the
         * given body.
         */
        void Add(const ForceRegistration& fr);

        /*!
         * Removes the given registered pair from the registry.
         */
        void Remove(RigidBody* body, ForceGenerator* fg);

        /*!
         * Removes the given registered pair from the registry.
         */
        void Remove(const ForceRegistration& fr);

        /*!
         * Clears all registrations from the registry.
         */
        void Clear();

        /*!
         * Calls all the force generators to update the forces of
         * their corresponding bodies.
         */
        void UpdateForces(real duration);
    };
}

#endif // PHXFORCEREGISTRY_H_INCLUDE_GUARD